----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 41273 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 0
SPELL.m_sName = "Riposte"
SPELL.m_sToolTip = "Gain 30 armor and 15% Dodge and Parry for 3 seconds. Costs 50 Energy."
SPELL.m_sIcon = "devin/blackbetty/spells/warrior/shieldbarrier.png"
SPELL.m_iCoolDown = 1
SPELL.m_iManaCost = 50
SPELL.m_bRequiresTarget = false
SPELL.m_iSpellType = SPELLTYPE_MOBILITY
SPELL.m_bRecastWhileCasting = false

---------------------------------------------------------------------------------------

local range = 100
local weapondamage = 20

function SPELL:Cast( pl, target )
	print("Casted "..self.m_sName.."!")
	pl:EmitSound("devin/blackbetty/weapons/ShieldWall.wav", 100, 100)
	pl.ArmorStat = pl.ArmorStat + 30
	if(pl.shieldmodel != nil and IsValid(pl.shieldmodel))then
		pl.shieldmodel:Remove()
		pl.shieldmodel = nil
	end
	pl.shieldmodel = ents.Create("prop_dynamic")
	pl.shieldmodel:SetMoveParent(pl:GetWeapon("weapon_all"))
	pl.shieldmodel:SetPos(pl:GetPos() + Vector(0, 0, -38))
	pl.shieldmodel:SetAngles(pl:GetAngles())
	pl.shieldmodel:SetLocalAngles(Angle(0, 0, 0))
	pl.shieldmodel:SetModel(Model("models/devin/rpgdm/spellmodels/shield_wall.mdl"))
	pl.shieldmodel:DrawShadow( false )
	pl.shieldmodel:Spawn()
	pl.shieldmodel:Activate()
	pl.shieldmodel:SetModelScale( 1.2, 0 );
	pl.shieldmodel:SetRenderMode(RENDERMODE_TRANSALPHA)
	pl.shieldmodel:SetColor(Color(255, 255, 255, 50))

	local sequence = pl.shieldmodel:LookupSequence("idle")
	pl.shieldmodel:SetSequence(sequence)
	pl.shieldmodel:SetPlaybackRate(1.5)
	
	if(timer.Exists("sm_on_"..pl:EntIndex()..""))then
		timer.Destroy("sm_on_"..pl:EntIndex().."")
	end
	timer.Create("sm_on_"..pl:EntIndex().."", 3, 1, function() 
		if(pl.shieldmodel != nil)then
			pl.shieldmodel:Remove()
			pl.shieldmodel = nil
		end
	end)
	
	timer.Simple(3, function()
		pl:DoAnimationEvent(ACT_DI_ALYX_ZOMBIE_MELEE)
		pl:EmitSound("devin/blackbetty/weapons/whirlwind/whirlwind.wav", 100, 100)
		pl.ArmorStat = pl.ArmorStat - 30
		local whirlRadius = ents.FindInSphere(pl:GetPos(), 240)
		for i, s in ipairs(whirlRadius)do
			if(s and s:EntIndex() != pl:EntIndex() and s:IsPlayer() or s:IsNPC() or s:GetClass() == "npc_rpgdm")then
				self:Effect(pl, s)
			end
		end
	end)
end

function SPELL:Effect(pl, target)
	if(pl:IsPlayer())then
		weapon = pl:GetWeapon("weapon_all")
	else
		target = pl.Target
	end
	
	local dmginfo = DamageInfo()
		dmginfo:SetDamage(math.Round(math.random(weapon.MinWeaponDamage*0.75, weapon.MaxWeaponDamage*0.75))) --50 damage
		dmginfo:SetDamageType( DMG_SLASH ) --Bullet damage
		dmginfo:SetAttacker( pl ) --First player found gets credit
		dmginfo:SetDamageForce( Vector( 0, 0, 1000 ) ) --Launch upwards
	target:EmitSound("devin/blackbetty/weapons/GougeTarget.wav", 160, 100)
	target:TakeDamageInfo( dmginfo )
	ParticleEffect( "pummel_hit", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), pl )
	ParticleEffect( "player_blood", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), pl )
	if SERVER then
		target:SetVelocity(((pl:GetPos()- Vector(0, 0, 40)) - target:GetPos())*-3)
	end	
end




